package design.mode.controller;

import design.mode.bean.RequestParameter;
import design.mode.dispatcher.bean.BaseResponse;
import design.mode.dispatcher.bean.CaseRequest;
import design.mode.dispatcher.caseenum.CaseEnum;
import design.mode.dispatcher.caseenum.StatusCode;
import design.mode.dispatcher.util.InitCaseBeanMapComponent;
import design.mode.model.strategy.UserService;
import design.mode.service.CaseInterface;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ldanniel
 */
@RestController
@RequestMapping("/switch")
public class BaseController {
    @Autowired
    private UserService userService;
    @PostMapping("/getResult")
    public List<String> getResult () throws Exception {
        return null;
    }













    @Autowired
    private InitCaseBeanMapComponent mapComponent;

    @PostMapping("/caseInfo")
    public BaseResponse caseInfo(@RequestBody RequestParameter requestParam){
        BaseResponse response=new BaseResponse(StatusCode.Success);
        try {
            CaseRequest request=new CaseRequest(requestParam.getType(),requestParam.getName());

            CaseEnum caseEnum=CaseEnum.valueOf(request.getType());
            CaseInterface caseInterface= mapComponent.getProcessMap().get(caseEnum);
            response.setData(caseInterface.execute(request));
        }catch (Exception e){
            response=new BaseResponse(StatusCode.Failure.getCode(),e.getMessage());
        }
        return response;
    }
    @RequestMapping(value = "/hello",method = RequestMethod.GET)
    public String hello(){
        return "hello";
    }




}
